const express=require("express")
const router=express.Router()
const mongoose=require("mongoose")
const Goods=require("../models/goods")

mongoose.connect("mongodb://127.0.0.1:27017/dumall",{
  useNewUrlParser: true,
  useUnifiedTopology: true
})

mongoose.connection.on("connected",function () {
  console.log("success");
  
})
mongoose.connection.on("error", function () {
  console.log("fail");

})
mongoose.connection.on("disconnected", function () {
  console.log("disconnected");

})
router.get("/",function(req,res,next){
  //res.send('hello,goods list')
  //console.log(Goods);
  Goods.find({},function(err,doc){
    if (err) {
      res.json({
        status:"1",
        msg:err.message
      })
    } else {
      res.json({
        status: "0",
        msg: "",
        result:{
          count:doc.length,
          list:doc
        }
      })
    }
  })
})

module.exports=router